package com.ruoyi.major.controller;

import com.ruoyi.major.domain.Major;
import com.ruoyi.major.service.IMajorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "基础管理-专业信息")
@RestController
@RequestMapping("/major")
public class MajorController extends BaseController {

    @Autowired
    private IMajorService majorService;

    @ApiOperation("专业管理 - 分页查询列表")
    @GetMapping("/list")
    public AjaxResult list() {
        List<Major> list = majorService.selectMajorList();
        return success(list);
    }

    @ApiOperation("专业管理 - 根据ID获取详细信息")
    @GetMapping("/info")
    public AjaxResult getInfo(@RequestParam Long id) {
        return success(majorService.selectMajorById(id));
    }



    @PostMapping
    @ApiOperation("专业管理 - 新增数据")
    @Log(title = "专业信息", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody Major major) {
        return toAjax(majorService.insertMajor(major));
    }

    @PutMapping
    @ApiOperation("专业管理 - 修改数据")
    @Log(title = "专业信息", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody Major major) {
        return toAjax(majorService.updateMajor(major));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("专业管理 - 删除数据")
    @Log(title = "专业信息", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(majorService.deleteMajorByIds(ids));
    }
}
